package thread;

/**
 * 线程中断
 */
public class SleepDemo2 {
    public static void main(String[] args) {

        Thread wkj = new Thread("王氪金"){//线程可以有名字
            @Override
            public void run() {
                try {
                    System.out.println(getName()+"累了睡一会儿");//创建匿名内部类,匿名内部类也是Thread的派生类,所有可以直接调用getName方法
                    Thread.sleep(1000000);
                } catch (InterruptedException e) {
                    System.out.println("谁呀!谁呀!谁呀!");
                }
                System.out.println(getName()+"醒了");
            }
        };

        Thread fcq = new Thread("饭传奇"){
            @Override
            public void run() {
                System.out.println(getName()+"中午去哪儿吃饭呢?");
                try {
                    Thread.sleep(8000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                wkj.interrupt();
            }
        };

        wkj.start();
        fcq.start();
    }
}
